/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AdminEditProduct;
import java.sql.*;
import DBManager.DBConnection;
import java.util.Date;
/**
 *
 * @author maconcon
 */
public class EditProductManager1 {
    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.

/**
 *
 * @author maconcon
 */

    public boolean editProduct(Products newProduct)
    {
        boolean result = false;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
            PreparedStatement pstmt =
                conn.prepareStatement("UPDATE products SET title=?,synopsis=?,"
                    + "  price=? , type=? where productid=? ");

            //append values for the parameters
            int i=1;
            
               pstmt.setString(i++, newProduct.getTitle1());
               pstmt.setString(i++, newProduct.getSynopsis1());
               pstmt.setInt(i++, newProduct.getPrice1());
               pstmt.setString(i++, newProduct.getType1());
                 pstmt.setInt(i++, newProduct.getProductid1());
               
            //execute SQL statement
            pstmt.executeUpdate();

            result = true;
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
    
    
         public int Log(int x,Products manager)
    { Date newDate = new java.util.Date();
       int result=0;
         String status;
        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn =  db.getConnection();
             java.util.Date time = new java.util.Date();
             
                        
             //String query="insert into logadmin(adminid,message) values(?,?)";
       String message="Admin updated product\n"+newDate+"\n"+ manager.getTitle1()+"\n"+ manager.getSynopsis1()+"\n"+manager.getType1()+"\n"+manager.getPrice1();
                 
            PreparedStatement pstmt =  conn.prepareStatement("insert into logadmin(adminid,message) values(?,?)");
            
            //append values for the parameters
            int i = 1;
            pstmt.setInt(i++, x);
            pstmt.setString(i++, message);
           
            pstmt.executeUpdate();
result=1;
            //execute SQL statement
         
          
        }
        catch(SQLException ex){ex.printStackTrace();}
        
        return result;
    }    
     
}


